var tag=null;
var sound=null;
var vibration=null;
var wifi=null;
var bluetooth=null;
var hwflag=null;
var swflag=null;
var todo=null;

var insertdao = function(event) {
	tag = $('#tag').val();
	if(validation()){
		hwflag = $('#checkbox1').val();
		swflag = $('#checkbox2').val();
		sound = $('#sound').val();
		vibration = $('input[name = "vibration"]:checked').attr('value');
		wifi = $('input[name = "wifi"]:checked').attr('value');
		bluetooth = $('input[name = "bluetooth"]:checked').attr('value');
		todo =  $('input[name = "nxtsetting"]:checked').attr('value');

		ProfileHandler.insert(hwflag, swflag, tag, sound, vibration, wifi, bluetooth, todo);

		ProfileHandler.showToast("Saved");
		window.location.href = "main.html";
		event.preventDefault();
	} else {
		return false;
	}
};


var updatedao = function(event) {
	tag = $('#tag').val();
	hwflag = $('#checkbox1').val();
	swflag = $('#checkbox2').val();
	sound = $('#sound').val();
	vibration = $('input[name = "vibration"]:checked').attr('value');
	wifi = $('input[name = "wifi"]:checked').attr('value');
	bluetooth = $('input[name = "bluetooth"]:checked').attr('value');
	todo =  $('input[name = "nxtsetting"]:checked').attr('value');
	ProfileHandler.update(hwflag, swflag, tag, sound, vibration, wifi, bluetooth, todo);
	ProfileHandler.showToast("Updated");
	//window.location.href = "main.html";  ->첫 페이지로 돌아가는 부분 막아놓음
	event.preventDefault();
};

var detaildao = function(event) {
	ProfileHandler.showToast(tag);
	return ProfileHandler.detail(tag);
}

var selectdao = function(){
	return ProfileHandler.select();
};

var deletedao = function(event) {
	ProfileHandler.showToast(tag);
	return ProfileHandler.del(tag);
	event.preventDefault();
}

var join =  function(event) {
	ProfileHandler.tagjoin();
	event.preventDefault();
};


var validation = function(event) {
	var space = /[\s]/g;
	var specialChars = /[`!@#$%^&*|\\\'\";:\/?]/gi;

	if (tag == 0) {
		ProfileHandler.showToast("Please input a tag.");
		return false;
	}else if(space.test(tag)){
		ProfileHandler.showToast("You can not use space characters.");
		return false;		
	}
	else if(specialChars.test(tag)){
		ProfileHandler.showToast("You may not enter special characters.");
		return false;
	}
	else{
		var db = ProfileHandler.validation(tag);
		if(db == 1){
			ProfileHandler.showToast("Your input is duplicated.");
			return false;
		}
	}
	return true;
}
